/*
 * MouseWheelEvent.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.events;

import com.cute4j.swing.Component;

/**
 * Mouse Wheel Event.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class MouseWheelEvent extends MouseEvent {

// Public Static Fields. -------------------------------------------------------

  /**
   * Scrolling by units (lines).
   */
  public static final int WHEEL_UNIT_SCROLL = 0;

  /**
   * Scrolling by blocks (pages).
   */
  public static final int WHEEL_BLOCK_SCROLL = 1;

// Private Static Fields. ------------------------------------------------------

  private static final long serialVersionUID = -2444018698352656717L;

// Private Fields. -------------------------------------------------------------

  private final int scrollType;
  private final int scrollAmount;
  private final int wheelRotation;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new MouseWheelEvent object.
   *
   * @param source the source component
   * @param id the event id
   * @param when the time the event occurred
   * @param modifiers the modifiers
   * @param x the x coordinate of the mouse point
   * @param y the y coordinate of the mouse point
   * @param clickCount the click count
   * @param scrollType the scroll type
   * @param scrollAmount the scroll amount
   * @param wheelRotation the wheel rotation
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public MouseWheelEvent(Component source, int id, long when, int modifiers,
                         int x, int y, int clickCount, int scrollType,
                         int scrollAmount, int wheelRotation) {
    super(source, id, when, modifiers, x, y, clickCount);
    this.scrollType = scrollType;
    this.scrollAmount = scrollAmount;
    this.wheelRotation = wheelRotation;
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns scroll type.
   *
   * @return scroll type
   */
  public int getScrollType() {
    return scrollType;
  }

  /**
   * Returns scroll amount.
   *
   * @return scroll amount
   */
  public int getScrollAmount() {
    return scrollAmount;
  }

  /**
   * Returns wheel rotation.
   *
   * @return wheel rotation
   */
  public int getWheelRotation() {
    return wheelRotation;
  }

  /**
   * Returns the number of units to scroll.
   *
   * @return the number of units to scroll
   */
  public int getUnitsToScroll() {
    return scrollAmount * wheelRotation;
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public String paramString() {
    StringBuffer sb = new StringBuffer(160);
    sb.append(super.paramString());
    sb.append(",scrollType=");
    switch (getScrollType()) {
      case WHEEL_UNIT_SCROLL:
        sb.append("WHEEL_UNIT_SCROLL");
        break;
      case WHEEL_BLOCK_SCROLL:
        sb.append("WHEEL_BLOCK_SCROLL");
        break;
      default:
        sb.append("unknown scroll type");
        break;
    }
    sb.append(",scrollAmount=");
    sb.append(getScrollAmount());
    sb.append(",wheelRotation=");
    sb.append(getWheelRotation());
    return sb.toString();
  }

}
